package com.yituo.mjworld.mvc.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.yituo.mjworld.mvc.entity.web.WebReturnRequest;
import com.yituo.mjworld.core.web.core.BaseForm;
import com.yituo.mjworld.mvc.form.DeleteForm;
import com.yituo.mjworld.mvc.form.QueryForm;
import com.yituo.mjworld.mvc.service.BaseService;
import com.yituo.mjworld.core.web.core.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ReturnRequestServiceImpl extends BaseService {
  /**
   * 获取清单
   *
   * @param form
   * @return
   */
  @Override
  public JSONObject getList(QueryForm form) {
    String sql = "select * from WebReturnRequest order by createDate desc";
    String countSql = "select count(id) from WebReturnRequest";
    return get(sql, countSql, form, null);
  }

  /**
   * 删除记录
   *
   * @param form
   * @return
   */
  @Override
  public Result delete(DeleteForm form) {
    return null;
  }

  /**
   * 保存或者更新
   *
   * @param baseForm
   * @return
   */
  @Override
  public Result saveOrUpdate(BaseForm baseForm) {
    WebReturnRequest form = (WebReturnRequest) baseForm;
    WebReturnRequest msg = (WebReturnRequest) baseDao.get(WebReturnRequest.class, form.getId());
    if (msg == null) {
      return null;
    }
    BeanUtils.copyProperties(msg, form);
    msg.setProcessDate(new Date());
    baseDao.saveOrUpdate(msg);
    return new Result().setResult(true).setMsg(msg);
  }
}
